#!/usr/bin/env python
# Create: 2018/10/22
__author__ = '749B'
"""grequests"""

import grequests
from bs4 import BeautifulSoup

url_list = [
    'https://github.com/explore',
    'https://www.djangoproject.com/',
    'http://www.python-requests.org/en/master/',
    'https://jquery.com/',
    'https://getbootstrap.com/',
    'https://www.solarwinds.com/',
    'https://www.zabbix.com/',
    'http://open-falcon.org/',
    'https://www.python.org/',
    'http://www.jetbrains.com/',
]


def exception_handler(request, exception):
    print(request, exception)
    print("Request failed")


def callback(r, *args, **kwargs):
    r.encoding = 'utf-8'
    soup = BeautifulSoup(r.text, features='html.parser')
    title = soup.find('title')
    print(title)


if __name__ == '__main__':
    request_list = [grequests.get(url, timeout=10, callback=callback) for url in url_list]
    response_list = grequests.map(request_list, exception_handler=exception_handler, gtimeout=11)
    print(response_list)



